<#--接口加密模块-->
<#if charListReqId??>
    <#list charListReqId as char>
var s_req_${char?index}='${char}';
    <#--混淆部分-->
        <#if char?index gte 0 >
            <#list charListReqId as nestedItem>
var s_req_${char?index}_${nestedItem?index}='${nestedItem}';
            </#list>
        </#if>
    </#list>
</#if>
<#--秘钥-->
<#list charListSecretKey as char>
 var s_char_${char?index}='${char}';
<#--混淆部分-->
 <#if char?index gte 0 >
     <#list charListSecretKey as nestedItem>
var s_char_${char?index}_${nestedItem?index}='${nestedItem}';
     </#list>
 </#if>
</#list>


<#if charListSessionId??>
<#--会话-->
<#list charListSessionId as char>
var s_cha_${char?index}='${char}';
<#--混淆部分-->
<#if char?index gte 0 >
    <#list charListSessionId as nestedItem>
var s_cha_${char?index}_${nestedItem?index}='${nestedItem}';
    </#list>
</#if>
</#list>
</#if>
var secrypt_s_mode={
    getsecryptkey:function(){
        let sk=this.get_seck_t();
        return CryptoJS.enc.Utf8.parse(sk);
    },
<#--  加密-->
    getEncrypt:function(plaintText){
        let secryptkey=this.getsecryptkey();
        return CryptoJS.AES.encrypt(plaintText, secryptkey, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
    },
<#--reqId-->
<#if insertedIndicesReqId??>
    getReqId_l:function(){
        return this.getCharReqStr_${insertedIndicesReqId?size - 1}();
    },
    getReqId_t:function(){
        let s=this.getReqId_l();
        return this.decodeStr(s);
    },
<#list insertedIndicesReqId as item>
    getCharReqStr_${item?index}:function(){
    <#if item?index == 0>
        return s_req_${item};
    <#else>
        return this.getCharReqStr_${item?index - 1}()+ s_req_${item};
    </#if>
    },
<#--    混淆部分 -->
    <#if item?index gte 0 >
        <#list insertedIndicesReqId as nestedItem>
    getCharReqStr_${item?index}_${nestedItem?index}:function(){
            return this.getCharReqStr_${nestedItem?index - 1}()+ s_req_${nestedItem};
    },
        </#list>
    </#if>
</#list>
</#if>

<#if isDecrypt?? && isDecrypt==true >
<#--解密-->
    getDecrypt:function(encryptText){
        let secryptkey=this.getsecryptkey();
        let decrypted = CryptoJS.AES.decrypt(encryptText, secryptkey, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        let decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
        return decryptedText;
    },
</#if>
    decodeStr:function(v){
        return decodeURIComponent(escape(atob(v)));
    },
<#--秘钥-->
<#list insertedIndicesSecretKey as item>
    getCharStr_${item?index}:function(){
    <#if item?index == 0>
        return s_char_${item};
    <#else>
        return this.getCharStr_${item?index - 1}()+ s_char_${item};
    </#if>
    },
<#--    混淆部分 -->
<#if item?index gte 0 >
    <#list insertedIndicesSecretKey as nestedItem>
        getCharStr_${item?index}_${nestedItem?index}:function(){
            return this.getCharStr_${nestedItem?index - 1}()+ s_char_${nestedItem};
        },
    </#list>
</#if>
</#list>

<#--会话id-->
<#if insertedIndicesSessionId??>
<#list insertedIndicesSessionId as item>
    getSCharStr_${item?index}:function(){
    <#if item?index == 0>
        return s_cha_${item};
    <#else>
        return this.getSCharStr_${item?index - 1}()+ s_cha_${item};
    </#if>
    },
<#--    混淆部分-->
<#if item?index gte 0 >
    <#list insertedIndicesSessionId as nestedItem>
    getSCharStr_${item?index}_${nestedItem?index}:function(){
         return this.getSCharStr_${nestedItem?index - 1}()+ s_char_${nestedItem};
    },
    </#list>
</#if>
</#list>
</#if>
    get_seck:function(){
        return this.getCharStr_${insertedIndicesSecretKey?size - 1}();
    },
    get_seck_t:function(){
       let s=this.get_seck();
        return this.decodeStr(s);
    },
<#if insertedIndicesSessionId??>
    getse_ky_t:function(){
        return this.getSCharStr_${insertedIndicesSessionId?size - 1}();
    },
    gets_ky:function(){
        let s=this.getse_ky_t();
        return this.decodeStr(s);
    },
</#if>
<#--加密请求-->
    encryptFormData:function(url,reqData,callback){
        const formData = new FormData();
        let s=this.getReqId_t();
        formData.append('sessionId', s);
        let reqStr=JSON.stringify(reqData);
        reqStr=this.getEncrypt(reqStr);
        formData.append('reqStr', reqStr);
        fetch(url, {
            method: 'POST',
            body: formData, // 直接传递 FormData
        }).then(response => {
            if (!response.ok) {
                throw new Error('fail: ' + response.statusText);
            }
            return response.json(); // 假设服务器返回 JSON 数据
        }).then(data => {
            if(data.code==200){
                if(data.data){
                    let respStr=this.getDecrypt(data.data);
                    try {
                        data.data=JSON.parse(respStr);
                    }catch (e){
                        data.data=respStr;
                    }
                    callback(data);
                }else{
                    callback(data);
                }
            }else{
                callback(data);
            }
        })
        .catch(error => {
            console.error('请求失败:', error);
        });
    }
}
